using Game.Core;
using Game.Manager;
using Game.XH;
using UnityEngine;

namespace Game.Component.Character
{
	public class Body : CharacterComponent
	{
		public Transform tops;

		public Transform topsBack;

		public Transform pants;

		public Transform topsIcon;

		public int bodyId;

		public int topsId;

		public int topsIconId;

		public int pantsId;

		public Color32 bodyColor;

		public Body(Transform trans, int bodyZ, int topsZ, int topsBackZ, int topsIconZ, int pantsZ)
			: base(trans)
		{
			spriteTrans.SetLocalZ((float)bodyZ * 1E-05f);
			tops = trans.Find("Tops");
			tops.SetLocalZ((float)topsZ * 1E-05f);
			topsBack = tops.Find("Back");
			topsBack.SetLocalZ((float)topsBackZ * 1E-05f);
			topsIcon = tops.Find("Icon");
			topsIcon.SetLocalZ((float)topsIconZ * 1E-05f);
			pants = trans.Find("Pants");
			pants.SetLocalZ((float)pantsZ * 1E-05f);
		}

		public void SetBody(int id, Transform copy, Color32 color)
		{
			if (bodyId != id)
			{
				bodyId = id;
				ChangeSprite(copy);
				SetColor(color);
			}
		}

		public void SetColor(Color32 color)
		{
			bodyColor = color;
			if (spriteRenderer != null)
			{
				spriteRenderer.color = bodyColor;
			}
		}

		public void SetTops(int id, Transform copy, Transform backcopy)
		{
			if (topsId != id)
			{
				topsId = id;
				ChangeSprite(tops, copy);
				if (backcopy != null)
				{
					ChangeSprite(topsBack, backcopy);
				}
			}
		}

		public void SetBoxColliderEnabled(bool val)
		{
			BoxCollider2D component = transform.GetComponent<BoxCollider2D>();
			if (component != null)
			{
				component.enabled = val;
			}
		}

		public void SetTopsIcon(int id)
		{
			if (topsIconId != id)
			{
				topsIconId = id;
				if (topsIconId < 1)
				{
					topsIcon.Find("Sprite").GetComponent<SpriteRenderer>().sprite = null;
				}
				else
				{
					topsIcon.Find("Sprite").GetComponent<SpriteRenderer>().sprite = Singleton<AssetBundleManager>.Instance.GetTopsIcon(topsIconId);
				}
			}
		}

		public void SetPants(int id, Transform copy)
		{
			if (pantsId != id)
			{
				pantsId = id;
				ChangeSprite(pants, copy);
			}
		}
	}
}
